import socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
address = ('localhost', 9999)
server_socket.bind(address)
server_socket.listen()
print('服务器正在监听 {}'.format(address))
client_socket, client_address = server_socket.accept()
print('接受来自 {} 的连接'.format(client_address))
while True:
    data = client_socket.recv(1024).decode('utf-8')
    if not data:
        break
    print('客户端说: {}'.format(data))
    message = input('请输入要发送给客户端的消息: ')
    client_socket.send(message.encode('utf-8'))
    if input("是否要继续？Y/N")=="N":
        break
client_socket.close()
server_socket.close()